/* GUI CONVERTED from sqqoso.p (converter v1.76) Fri Jul 26 02:16:35 2002 */
/* sqqoso.p - RELEASE QUOTE TO SALES ORDER                                    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.20.1.7 $                                                      */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 4.0      LAST MODIFIED: 12/12/88   BY: jms *A548*                */
/* REVISION: 6.0      LAST MODIFIED: 04/17/90   BY: ftb *D002*                */
/* REVISION: 6.0      LAST MODIFIED: 05/22/90   BY: WUG *D022*                */
/* REVISION: 6.0      LAST MODIFIED: 07/06/90   BY: EMB *D040*                */
/* REVISION: 6.0      LAST MODIFIED: 11/26/90   BY: afs *D225*                */
/* REVISION: 6.0      LAST MODIFIED: 12/21/90   BY: MLB *D238*                */
/* REVISION: 6.0      LAST MODIFIED: 03/14/91   BY: afs *D436*                */
/* REVISION: 6.0      LAST MODIFIED: 05/31/91   BY: WUG *D664*                */
/* REVISION: 7.0      LAST MODIFIED: 09/17/91   BY: MLV *F015*                */
/* REVISION: 7.0      LAST MODIFIED: 10/11/91   BY: emb *F024*                */
/* REVISION: 7.0      LAST MODIFIED: 10/30/91   BY: MLV *F029*                */
/* REVISION: 7.0      LAST MODIFIED: 01/29/92   BY: afs *F106*                */
/* REVISION: 7.0      LAST MODIFIED: 03/26/92   BY: tmd *F325*                */
/* REVISION: 7.0      LAST MODIFIED: 03/27/92   BY: dld *F326*                */
/* REVISION: 7.0      LAST MODIFIED: 04/09/92   BY: emb *F369*                */
/* REVISION: 7.0      LAST MODIFIED: 04/10/92   BY: dld *F358*                */
/* REVISION: 7.0      LAST MODIFIED: 04/06/92   BY: afs *F356*                */
/* REVISION: 7.0      LAST MODIFIED: 05/11/92   BY: tjs *F444*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 05/22/92   BY: afs *F518*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 06/09/92   BY: tjs *F504*                */
/* REVISION: 7.3      LAST MODIFIED: 09/12/92   BY: tjs *G035*                */
/* REVISION: 7.3      LAST MODIFIED: 09/23/92   BY: tjs *G086*                */
/* REVISION: 7.3      LAST MODIFIED: 09/27/92   BY: jcd *G247*                */
/* REVISION: 7.3      LAST MODIFIED: 11/04/92   BY: emb *G272*                */
/* REVISION: 7.3      LAST MODIFIED: 11/18/92   BY: tjs *G191*                */
/* REVISION: 7.3      LAST MODIFIED: 12/01/92   BY: emb *G378*                */
/* REVISION: 7.3      LAST MODIFIED: 01/11/93   BY: mpp *G485*                */
/* REVISION: 7.3      LAST MODIFIED: 02/02/93   BY: tjs *G620*                */
/* REVISION: 7.3      LAST MODIFIED: 02/09/93   BY: bcm *G415*                */
/* REVISION: 7.3      LAST MODIFIED: 02/18/93   BY: afs *G692*                */
/* REVISION: 7.3      LAST MODIFIED: 02/26/93   BY: tjs *G754*                */
/* REVISION: 7.3      LAST MODIFIED: 06/17/93   BY: tjs *G830*                */
/* REVISION: 7.3      LAST MODIFIED: 08/09/93   BY: DPM *GE02*                */
/* REVISION: 7.4      LAST MODIFIED: 08/28/93   BY: bcm *H094*                */
/* REVISION: 7.4      LAST MODIFIED: 11/18/93   BY: tjs *H082*                */
/* REVISION: 7.4      LAST MODIFIED: 04/12/94   BY: afs *FN35*                */
/* REVISION: 7.4      LAST MODIFIED: 06/09/94   BY: WUG *GK20*                */
/* REVISION: 7.4      LAST MODIFIED: 07/05/94   BY: tjs *FN95*                */
/* REVISION: 7.4      LAST MODIFIED: 06/22/94   BY: WUG *GK60*                */
/* REVISION: 7.4      LAST MODIFIED: 10/24/94   BY: afs *FS77*                */
/* REVISION: 7.4      LAST MODIFIED: 10/31/94   BY: afs *H587*                */
/* REVISION: 7.4      LAST MODIFIED: 11/14/94   BY: dpm *FT57*                */
/* REVISION: 7.4      LAST MODIFIED: 11/22/94   BY: bcm *H606*                */
/* REVISION: 7.4      LAST MODIFIED: 01/12/95   BY: ais *F0C7*                */
/* REVISION: 7.4      LAST MODIFIED: 02/01/95   BY: bcm *F0G8*                */
/* REVISION: 7.4      LAST MODIFIED: 02/15/95   BY: rxm *G0F4*                */
/* REVISION: 7.4      LAST MODIFIED: 02/24/95   BY: rxm *F0KB*                */
/* REVISION: 7.4      LAST MODIFIED: 04/06/95   BY: rxm *G0K8*                */
/* REVISION: 8.5      LAST MODIFIED: 03/28/95   BY: NTE *J042*                */
/* REVISION: 7.4      LAST MODIFIED: 07/06/95   BY: kjm *G0RS*                */
/* REVISION: 7.4      LAST MODIFIED: 09/20/95   BY: JYM *G0XM*                */
/* REVISION: 8.5      LAST MODIFIED: 03/04/96   BY: DAH *J0DH*                */
/* REVISION: 8.6      LAST MODIFIED: 09/29/97   BY: Joe Gawel    *K0K6*       */
/* REVISION: 8.6      LAST MODIFIED: 11/04/97   BY: Jerry Zhou   *K15N*       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 03/26/98   BY: *H1J6* Niranjan R.        */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 06/11/98   BY: *L02K* Russ Witt          */
/* REVISION: 8.6E     LAST MODIFIED: 06/15/98   BY: *L02G* E. Janse           */
/* REVISION: 8.6E     LAST MODIFIED: 11/03/98   BY: *J33C* Manish K.          */
/* REVISION: 8.6E     LAST MODIFIED: 09/28/99   BY: *L0J4* Satish Chavan      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/09/00   BY: *M0QW* Falguni D.         */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* Mark Brown         */
/* REVISION: 9.2      LAST MODIFIED: 01/10/02   BY: *L194* Ashwini G.         */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.20.1.6    BY: Jean Miller       DATE: 05/10/02  ECO: *P05M*  */
/* $Revision: 1.20.1.7 $   BY: K Paneesh         DATE: 07/24/02  ECO: *N1PM*  */
/* $Revision: Eb2 Sp3 $  BY: Joy Huang         DATE: 12/22/03  ECO: *hk-s-014*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE */

/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}

/* NEW SHARED VARIABLES, BUFFERS AND FRAMES */

define new shared variable so_db      like dc_name.
define new shared variable orddate    like so_ord_date.
define new shared variable sonbr      like so_nbr label "Next Sales Order".
define new shared variable tax-edited like mfc_logical.
define new shared variable tax-prompt like mfc_logical.
define new shared variable qo_recno   as recid.
define new shared variable invalid    as logical no-undo.
define new shared variable calc_fr    like mfc_logical
   label "Recalculate Freight" no-undo.

/* LOCAL VARIABLES, BUFFERS AND FRAMES */
define variable auto_nbr      as logical.
define variable cnt           as integer.
define variable complete_flag like mfc_logical.
define variable cust          like qo_cust.
define variable cust1         like qo_cust.
define variable cycle         like qo_cycle.
define variable nbr           like qo_nbr.
define variable nbr1          like qo_nbr.
define variable ord           like qo_ord_date.
define variable ord1          like qo_ord_date.
define variable mc-rate       like exr_rate no-undo.
define variable mc-rate2      like exr_rate no-undo.

/*hk-s-014*/ define variable nrm-seq-num like qo_nbr init "".
/*hk-s-014*/ define variable nrmnbr     like nr_seqid. 

{etvar.i &new = "new"}
{etrpvar.i &new = "new"}
{etdcrvar.i "new"}


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
cycle   colon 25
   nbr     colon 25   nbr1     label "To" colon 49
   cust    colon 25   cust1    label "To" colon 49
   ord     colon 25   ord1     label "To" colon 49 skip(1)
   sonbr   colon 25
   orddate colon 25
   skip(1)
   calc_fr colon 25
with frame a side-labels width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* READ CONTROL FILE */

so_db = global_db.

mainloop:
repeat:

   if nbr1  = hi_char then nbr1 = "".
   if cust1 = hi_char then cust1 = "".
   if ord   = low_date then ord = ?.
   if ord1  = hi_date  then ord1 = ?.
   if auto_nbr then sonbr = "".

   assign
      orddate  = today
      cnt      = 0
      calc_fr  = no.

   update
      cycle
      nbr nbr1
      cust cust1
      ord ord1
      sonbr
      orddate
      calc_fr
   with frame a.

   assign
      auto_nbr = (sonbr = "")
      tax-edited = no
      tax-prompt = yes.

   bcdparm = "".
   {mfquoter.i cycle }
   {mfquoter.i nbr }
   {mfquoter.i nbr1 }
   {mfquoter.i cust }
   {mfquoter.i cust1 }
   {mfquoter.i ord }
   {mfquoter.i ord1 }
   {mfquoter.i sonbr }
   {mfquoter.i orddate }
   {mfquoter.i calc_fr }

   if nbr1 = ""
   then
      nbr1 = hi_char.

   if cust1 = ""
   then
      cust1 = hi_char.

   if ord = ?
   then
      ord = low_date.

   if ord1 = ?
   then
      ord1 = hi_date.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "printer"
               &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   /* Create Page Title Block */
   {mfphead.i}

   /* CYCLE THROUGH QUOTE MASTERS */
   qoloop:
   for each qo_mstr
      where qo_nbr >= nbr and qo_nbr <= nbr1
        and qo_cust >= cust and qo_cust <= cust1
        and qo_ord_date >= ord and qo_ord_date <= ord1
        and qo_cycle = cycle
        and qo_release = yes
   no-lock by qo_nbr:

      /* CHANGED FOURTH INPUT PARAMETER QO_ORD_DATE TO ORDDATE */
      if qo_curr <> base_curr and qo_fix_rate <> yes then do:
         {gprunp.i "mcpl" "p" "mc-get-ex-rate"
            "(input base_curr,
              input qo_curr,
              input """",
              input  orddate,
              output mc-rate2,
              output mc-rate,
              output mc-error-number)"}
      end . /* IF QO_CURR <> BASE_CURR  */
      if mc-error-number <> 0 then do:
         /* INVALID EXCHANGE RATE */
         {pxmsg.i &MSGNUM=2034 &ERRORLEVEL=2 &MSGARG1=qo_nbr}
         if not batchrun then pause.
         next qoloop.
      end.

      complete_flag = yes.

      for each qod_det where qod_nbr = qo_nbr no-lock:

         if (qod_qty_quot > 0  and  qod_rel_chg  > 0) or
            (qod_qty_quot < 0  and  qod_rel_chg  < 0)
         then do:
            complete_flag = no.
            if global_db <> "" then do:
               find si_mstr where si_site = qod_site no-lock no-error.
               if not connected(si_db) then do:
                  /* Database is not connected */
                  {pxmsg.i &MSGNUM=2510 &ERRORLEVEL=4 &MSGARG1=si_db}
                  next qoloop.
               end.
            end.
            else
               leave.
         end.

      end.

      if complete_flag = no then do:

         /* GET NEXT SALES ORDER NUMBER */
         next_sonbr:
         do transaction:

            if auto_nbr then do:
               /* Get next sales order number with prefix */
/*hk-s-014     {mfnctrlc.i soc_ctrl soc_so_pre soc_so so_mstr so_nbr sonbr}*/

/*hk-s-014**  Begin ************ Generate a new Po Number from NRM ************/ 

         find first nrs_mstr where nrs_site = qo_site and 
              nrs_sonbr <> "" no-lock no-error.
         if available nrs_mstr then do:  
             assign nrmnbr = nrs_sonbr
             nrm-seq-num = "".  
               {gprunp.i "xxnrm" "p" "nr_dispense"
               "(input nrmnbr,
                 input TODAY,
                 output nrm-seq-num)"}    
                          
             if nrm-seq-num <> "" then assign sonbr = nrm-seq-num.

/*GUI*/ if global-beam-me-up then undo, leave.
         end.         
         else do:
             /* Get next sales order number with prefix */
             {mfnctrlc.i soc_ctrl soc_so_pre soc_so so_mstr so_nbr sonbr}        
         end.

/*hk-s-014** Ending *************** Generate a new Po Number from NRM *******************/

            end.

            /* Increment user-supplied next SO number */
            else repeat:

               if not can-find(so_mstr where so_nbr = sonbr) then
                  leave next_sonbr.

               /* Increment and validate the order number */
               {gprun.i ""gpnxtnbr.p"" "(input-output sonbr)"}

               if length(sonbr) > 8 then do:
                  /* # SOs created */
                  {pxmsg.i &MSGNUM=653 &ERRORLEVEL=1 &MSGARG1=cnt}
                  /* Last SO created: # */
                  {pxmsg.i &MSGNUM=654 &ERRORLEVEL=1 &MSGARG1=sonbr}
                  next mainloop.
               end.

            end.

         end.  /* Next SO number generation */

         qo_recno = recid(qo_mstr).
         {gprun.i ""sqqosoa.p""}

         if not invalid then
         do with frame ordfrm:

            /* SET EXTERNAL LABELS */
            setFrameLabels(frame ordfrm:handle).

            display
               qo_nbr       column-label "Quote No."
               qo_so_nbr    column-label "Order No."
               qo_cust      column-label "Customer"
               qo_site      column-label "Site"
               qo_req_date  column-label "Required Date"
               qo_ord_date  column-label "Order Date"
            with frame ordfrm down STREAM-IO /*GUI*/ .

            cnt = cnt + 1.

         end. /* If Not Invalid */

      end.

   end.

   /* # Sales Orders created */
   {pxmsg.i &MSGNUM=653 &ERRORLEVEL=1 &MSGARG1=cnt}

   if cnt > 0 then do:
      /* Last SO created: # */
      {pxmsg.i &MSGNUM=654 &ERRORLEVEL=1 &MSGARG1=sonbr}
   end.

   {mfrtrail.i}

end.
